<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>librf: resumef::awaitable_t&lt; _Ty &gt; 模板结构体 参考</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">librf
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'搜索');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','搜索');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><b>resumef</b></li><li class="navelem"><a class="el" href="structresumef_1_1awaitable__t.html">awaitable_t</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public 成员函数</a> &#124;
<a href="structresumef_1_1awaitable__t-members.html">所有成员列表</a>  </div>
  <div class="headertitle">
<div class="title">resumef::awaitable_t&lt; _Ty &gt; 模板结构体 参考</div>  </div>
</div><!--header-->
<div class="contents">

<p>用于包装‘异步函数’为‘可等待函数(awaitable function)’。  
 <a href="structresumef_1_1awaitable__t.html#details">更多...</a></p>
<div class="dynheader">
类 resumef::awaitable_t&lt; _Ty &gt; 继承关系图:</div>
<div class="dyncontent">
 <div class="center">
  <img src="structresumef_1_1awaitable__t.png" usemap="#resumef::awaitable_5Ft_3C_20_5FTy_20_3E_map" alt=""/>
  <map id="resumef::awaitable_5Ft_3C_20_5FTy_20_3E_map" name="resumef::awaitable_5Ft_3C_20_5FTy_20_3E_map">
<area href="structresumef_1_1awaitable__impl__t.html" title="awaitable_t&lt;&gt;的公共实现部分，用于减少awaitable_t&lt;&gt;的重复代码。" alt="resumef::awaitable_impl_t&lt; _Ty &gt;" shape="rect" coords="0,0,200,24"/>
  </map>
</div></div>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public 成员函数</h2></td></tr>
<tr class="memitem:af66d4b4a3ba5339873b2dd8353ae6db3"><td class="memTemplParams" colspan="2">template&lt;class U &gt; </td></tr>
<tr class="memitem:af66d4b4a3ba5339873b2dd8353ae6db3"><td class="memTemplItemLeft" align="right" valign="top">void&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="structresumef_1_1awaitable__t.html#af66d4b4a3ba5339873b2dd8353ae6db3">set_value</a> (U &amp;&amp;value) const</td></tr>
<tr class="memdesc:af66d4b4a3ba5339873b2dd8353ae6db3"><td class="mdescLeft">&#160;</td><td class="mdescRight">设置可等待函数的返回值。  <a href="structresumef_1_1awaitable__t.html#af66d4b4a3ba5339873b2dd8353ae6db3">更多...</a><br /></td></tr>
<tr class="separator:af66d4b4a3ba5339873b2dd8353ae6db3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="inherit_header pub_methods_structresumef_1_1awaitable__impl__t"><td colspan="2" onclick="javascript:toggleInherit('pub_methods_structresumef_1_1awaitable__impl__t')"><img src="closed.png" alt="-"/>&#160;Public 成员函数 继承自 <a class="el" href="structresumef_1_1awaitable__impl__t.html">resumef::awaitable_impl_t&lt; _Ty &gt;</a></td></tr>
<tr class="memitem:a22f1adeb8ecfd2c078f620dbc7c368a1 inherit pub_methods_structresumef_1_1awaitable__impl__t"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="structresumef_1_1awaitable__impl__t.html#a22f1adeb8ecfd2c078f620dbc7c368a1">set_exception</a> (std::exception_ptr e) const</td></tr>
<tr class="memdesc:a22f1adeb8ecfd2c078f620dbc7c368a1 inherit pub_methods_structresumef_1_1awaitable__impl__t"><td class="mdescLeft">&#160;</td><td class="mdescRight">发生了异常后，设置异常。  <a href="structresumef_1_1awaitable__impl__t.html#a22f1adeb8ecfd2c078f620dbc7c368a1">更多...</a><br /></td></tr>
<tr class="separator:a22f1adeb8ecfd2c078f620dbc7c368a1 inherit pub_methods_structresumef_1_1awaitable__impl__t"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2f7b2ef525186c9b7512dceb2453bebe inherit pub_methods_structresumef_1_1awaitable__impl__t"><td class="memTemplParams" colspan="2"><a id="a2f7b2ef525186c9b7512dceb2453bebe"></a>
template&lt;class _Exp &gt; </td></tr>
<tr class="memitem:a2f7b2ef525186c9b7512dceb2453bebe inherit pub_methods_structresumef_1_1awaitable__impl__t"><td class="memTemplItemLeft" align="right" valign="top">void&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="structresumef_1_1awaitable__impl__t.html#a2f7b2ef525186c9b7512dceb2453bebe">throw_exception</a> (_Exp e) const</td></tr>
<tr class="memdesc:a2f7b2ef525186c9b7512dceb2453bebe inherit pub_methods_structresumef_1_1awaitable__impl__t"><td class="mdescLeft">&#160;</td><td class="mdescRight">在协程内部，重新抛出之前设置的异常。 <br /></td></tr>
<tr class="separator:a2f7b2ef525186c9b7512dceb2453bebe inherit pub_methods_structresumef_1_1awaitable__impl__t"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a647bd5f5a5572bbbe8a17000ea5dc06d inherit pub_methods_structresumef_1_1awaitable__impl__t"><td class="memItemLeft" align="right" valign="top"><a id="a647bd5f5a5572bbbe8a17000ea5dc06d"></a>
<a class="el" href="structresumef_1_1future__t.html">future_type</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="structresumef_1_1awaitable__impl__t.html#a647bd5f5a5572bbbe8a17000ea5dc06d">get_future</a> () noexcept</td></tr>
<tr class="memdesc:a647bd5f5a5572bbbe8a17000ea5dc06d inherit pub_methods_structresumef_1_1awaitable__impl__t"><td class="mdescLeft">&#160;</td><td class="mdescRight">获得与之关联的future_t&lt;&gt;对象，作为可等待函数(awaitable function)的返回值。 <br /></td></tr>
<tr class="separator:a647bd5f5a5572bbbe8a17000ea5dc06d inherit pub_methods_structresumef_1_1awaitable__impl__t"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="inherited"></a>
额外继承的成员函数</h2></td></tr>
<tr class="inherit_header pub_attribs_structresumef_1_1awaitable__impl__t"><td colspan="2" onclick="javascript:toggleInherit('pub_attribs_structresumef_1_1awaitable__impl__t')"><img src="closed.png" alt="-"/>&#160;Public 属性 继承自 <a class="el" href="structresumef_1_1awaitable__impl__t.html">resumef::awaitable_impl_t&lt; _Ty &gt;</a></td></tr>
<tr class="memitem:af7b6df5bbe7392334d7914db0d878915 inherit pub_attribs_structresumef_1_1awaitable__impl__t"><td class="memItemLeft" align="right" valign="top"><a id="af7b6df5bbe7392334d7914db0d878915"></a>
<a class="el" href="structresumef_1_1counted__ptr.html">counted_ptr</a>&lt; <a class="el" href="structresumef_1_1state__t.html">state_type</a> &gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="structresumef_1_1awaitable__impl__t.html#af7b6df5bbe7392334d7914db0d878915">_state</a> = state_future_t::_Alloc_state&lt;<a class="el" href="structresumef_1_1state__t.html">state_type</a>&gt;(true)</td></tr>
<tr class="memdesc:af7b6df5bbe7392334d7914db0d878915 inherit pub_attribs_structresumef_1_1awaitable__impl__t"><td class="mdescLeft">&#160;</td><td class="mdescRight">管理的state_t&lt;&gt;对象。 <br /></td></tr>
<tr class="separator:af7b6df5bbe7392334d7914db0d878915 inherit pub_attribs_structresumef_1_1awaitable__impl__t"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">详细描述</h2>
<div class="textblock"><h3>template&lt;class _Ty&gt;<br />
struct resumef::awaitable_t&lt; _Ty &gt;</h3>

<p>用于包装‘异步函数’为‘可等待函数(awaitable function)’。 </p>
<p>通过返回一个‘可等待对象(awaitor)’，符合C++ coroutines的co_await所需的接口，来达成‘可等待函数(awaitable function)’。<br  />
这是扩展异步函数支持协程的重要手段。<br  />
<br  />
典型用法是申明一个 awaitable_t&lt;&gt;局部变量 awaitable，<br  />
在已经获得结果的情况下，直接调用 awaitable.set_value(value)设置返回值，使得可等待函数立即获得结果。<br  />
在不能立即获得结果的情况下，通过在异步的回调lambda里，捕获awaitable局部变量，<br  />
根据异步结果，要么调用 awaitable.set_value(value)设置结果值，要么调用 awaitable.set_exception(e)设置异常。<br  />
在设置值或者异常后，调用可等待函数的协程将得以继续执行。<br  />
此可等待函数通过 awaitable.get_future()返回与之关联的 future_t&lt;&gt;对象，作为协程的可等待对象。<br  />
<br  />
</p><dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">_Ty</td><td>可等待函数(awaitable function)的返回类型。<br  />
要求至少支持移动构造和移动赋值。<br  />
_Ty 支持特化为 _Ty&amp;，以及 void。 </td></tr>
  </table>
  </dd>
</dl>
</div><h2 class="groupheader">成员函数说明</h2>
<a id="af66d4b4a3ba5339873b2dd8353ae6db3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#af66d4b4a3ba5339873b2dd8353ae6db3">&#9670;&nbsp;</a></span>set_value()</h2>

<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;class _Ty &gt; </div>
<div class="memtemplate">
template&lt;class U &gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="structresumef_1_1awaitable__t.html">resumef::awaitable_t</a>&lt; _Ty &gt;::set_value </td>
          <td>(</td>
          <td class="paramtype">U &amp;&amp;&#160;</td>
          <td class="paramname"><em>value</em></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>设置可等待函数的返回值。 </p>
<p>_Ty的void特化版本，则是不带参数的set_value()函数。 </p><dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">value</td><td>返回值。必须支持通过value构造出_Ty类型。 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section attention"><dt>注意</dt><dd>与set_exception()互斥。调用了set_value(value)后，不能再调用set_exception(e)。 </dd></dl>

</div>
</div>
<hr/>该结构体的文档由以下文件生成:<ul>
<li>librf/src/<a class="el" href="awaitable_8h_source.html">awaitable.h</a></li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.17
</small></address>
</body>
</html>
